package com.dubbo.provider.serviceimpl;

import com.dubbo.api.UserService;
import com.dubbo.api.model.UserModel;
import com.dubbo.provider.entity.User;
import com.dubbo.provider.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

@Service //使用Dubbo提供的Service注解，注册暴露服务
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserModel getUser(Integer id) {
        User user = userMapper.selectByPrimaryKey(id);
        return this.convertPaperModelFromPaper(user);
    }

    //将user-》userModel
    private UserModel convertPaperModelFromPaper(User user){
        if(user == null){
            return null;
        }
        UserModel userModel = new UserModel();
        BeanUtils.copyProperties(user,userModel);
        return userModel;
    }
}
